home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World 2008 September
/
PCWorld_2008-09_cd.bin
/
v cisle
/
sadanastroju
/
bookmark_previews-0.6.5-fx.xpi
/
chrome
/
content
/
placesOrganizer.js
< prev
next >
Wrap
Text File
|
2008-05-27
|
29KB
|
762 lines
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
* http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Bookmark Previews extension.
*
* The Initial Developer of the Original Code is
* John Marshall <JohnM555@gmail.com>.
* Portions created by the Initial Developer are Copyright (C) 2007
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
* John Marshall <JohnM555@gmail.com>
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
var ThumbView = null;
function PreviewProvider(aRoot){
if (!aRoot)
aRoot = PlacesPreviewUtils.getViewRoot();
this.root = aRoot;
this.result = this.root.parentResult;
this._view = PlacesOrganizer._content.getResultView();
// var idx = view.treeIndexForNode(aNode);
// if (idx == 4294967295)
// idx=-1;
this.idx=-1;
var isOpen = this.idx==-1 || this._view.isContainerOpen(this.idx);
var rowCount = this._view.rowCount;
if (!(rowCount==0 || this.idx>=rowCount)){
this.level = this._view.getLevel(this.idx+1);
}
}
PreviewProvider.prototype = {
_idx: -1,
get length(){
return this._view.rowCount;
//return this.root.childCount;
},
getImage : function(idx){
var rowLevel = this._view.getLevel(idx);
if (rowLevel == this.level){
var node = this._view.nodeForTreeIndex(idx);
var aType = node.type;
if (aType!=Ci.nsINavHistoryResultNode.RESULT_TYPE_SEPARATOR){
return new PreviewImage(node);
}
}
return null;
/*var node = this.root.getChild(idx);
var aType = node.type;
if (aType!=Ci.nsINavHistoryResultNode.RESULT_TYPE_SEPARATOR){
return new PreviewImage(node);
}
return null;
*/
}
}
function PreviewImage(node){
this.url = node.uri
this.name = (node.title && node.title.length>0)?node.title:node.uri;
this.caption = this.name;
if (!(node instanceof Ci.nsINavHistoryContainerResultNode))
this.image = PlacesPreviewUtils.getImageForURL(this.url);
else
this.image = "chrome://bookmarkpreviews/skin/folder.png";
this.node = node;
}
var PlacesPreviewUtils = {
utils : {refreshDisplay:function(){}},
displayRoot : null,
contentDeck : null,
selected : null,
dir : null,
_initNamePicker: function EIO2_initNamePicker() {
var userEnteredNameField = this._element("userEnteredName");
var namePicker = this._element("namePicker");
var droppable = false;
userEnteredNameField.label = this._getItemStaticTitle();
// clean up old entries
var menupopup = namePicker.menupopup;
while (menupopup.childNodes.length > 2)
menupopup.removeChild(menupopup.lastChild);
if (this._microsummaries) {
this._microsummaries.removeObserver(this);
this._microsummaries = null;
}
var itemToSelect = userEnteredNameField;
try {
if (this._itemType == Ci.nsINavBookmarksService.TYPE_BOOKMARK &&
!this._readOnly)
this._microsummaries = PlacesUIUtils.microsummaries
.getMicrosummaries(this._uri, -1);
}
catch(ex) {
// getMicrosummaries will throw an exception in at least two cases:
// 1. the bookmarked URI contains a scheme that the service won't
// download for security reasons (currently it only handles http,
// https, and file);
// 2. the page to which the URI refers isn't HTML or XML (the only two
// content types the service knows how to summarize).
this._microsummaries = null;
}
if (this._microsummaries) {
var enumerator = this._microsummaries.Enumerate();
if (enumerator.hasMoreElements()) {
// Show the drop marker if there are microsummaries
droppable = true;
while (enumerator.hasMoreElements()) {
var microsummary = enumerator.getNext()
.QueryInterface(Ci.nsIMicrosummary);
var menuItem = this._createMicrosummaryMenuItem(microsummary);
if (PlacesUIUtils.microsummaries
.isMicrosummary(this._itemId, microsummary))
itemToSelect = menuItem;
menupopup.appendChild(menuItem);
}
}
this._microsummaries.addObserver(this);
}
/* changed here */
if (namePicker.selectedItem == itemToSelect || true){
namePicker.value = itemToSelect.label;
}
else{
namePicker.selectedItem = itemToSelect;
}
namePicker.setAttribute("droppable", droppable);
namePicker.readOnly = this._readOnly;
// clear the undo stack
var editor = namePicker.editor;
if (editor)
editor.transactionManager.clear();
},
init : function(){
/*
Small change to the initNamePicker function
Without this the name field will alternate between Bookmarks Toolbar(or possibly something else)
and the actual title. There has to be a better way to fix this, but I'm not sure
I think this stems from issues created by removing the editItem point and moving it outside the deck
*/
gEditItemOverlay._initNamePicker = PlacesPreviewUtils._initNamePicker;
//dump("preview init\n");
PlacesPreviewUtils.dir = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("ProfD", Components.interfaces.nsIFile);
PlacesPreviewUtils.dir.append("bookmarkpreviews");
if (!PlacesPreviewUtils.dir.exists())
PlacesPreviewUtils.dir.create(Components.interfaces.nsIFile.DIRECTORY_TYPE,0777);
ThumbView = document.getElementById("thumbnailView");
PlacesOrganizer._content.addEventListener("select",PlacesPreviewUtils.onSelectionChanged,false);
PlacesPreviewUtils.contentDeck = document.getElementById("contentDeck");
var modeMenus = {
thumbnails: document.getElementById("thumbnailsViewMenu"),
albums: document.getElementById("albumsViewMenu"),
details: document.getElementById("detailsViewMenu")
};
var commands = document.getElementById("previewsCommandSet").childNodes;
for (var i = 0; i<commands.length;i++){
var command = commands[i];
command.removeAttribute("persist");
command.removeAttribute("checked");
}
for each (var item in modeMenus){
item.removeAttribute("checked");
}
var view = document.getElementById("viewMenuPopup").getAttribute("view");
for (var mode in modeMenus){
if (mode == view){
dump("mode: "+mode+" checked: "+modeMenus[mode].getAttribute("checked")+"\n");
PlacesPreviewUtils.onSelectView(mode);
modeMenus[mode].setAttribute("checked","true");
break;
}
}
var listSplitter = PlacesOrganizer._places.nextSibling;
listSplitter.setAttribute("oncommand","PlacesPreviewUtils.onResize(event);");
addEventListener("resize",PlacesPreviewUtils.onResize,false);
/* Listen for when the previews get updated */
var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
observerService.addObserver(PlacesPreviewUtils, "bookmarkpreviews:preview-updated", false);
/*
Move the info pane outside of the deck so it can be used by the thumbnail view.
This needs to be in a setTimeout, otherwise a method in textbox's timeout will
throw.
*/
setTimeout(function(){
var contentView = PlacesPreviewUtils.contentDeck.parentNode;
var infoPane = document.getElementById("infoPaneBox");
if (!infoPane)//The newest name is infoPaneBox, but it was previously just infoPane. Support both
infoPane = document.getElementById("infoPane");
var namePicker = document.getElementById("editBMPanel_namePicker");
infoPane = infoPane.parentNode.removeChild(infoPane);
infoPane = contentView.appendChild(infoPane);
namePicker = document.getElementById("editBMPanel_namePicker");
namePicker.selectedIndex = 0;
},0);
},
uninit : function(){
PlacesOrganizer._content.removeEventListener("select",PlacesPreviewUtils.onSelectionChanged,false);
window.removeEventListener("resize",PlacesPreviewUtils.onResize,false);
var observerService = Components.classes["@mozilla.org/observer-service;1"]
.getService(Components.interfaces.nsIObserverService);
observerService.removeObserver(PlacesPreviewUtils, "bookmarkpreviews:preview-updated");
if (ThumbView.initiated)
ThumbView.uninit();
if (AlbumView.initiated)
AlbumView.uninit();
},
onResize : function(event){
if (PlacesPreviewUtils.utils.onResize)
PlacesPreviewUtils.utils.onResize(event);
},
sortChanged : function(event){
//dump("sort changed!-!-!-!\n");
},
onSelectView : function(type,event){
var evt = document.createEvent("MouseEvents");
evt.initMouseEvent("click", true, true, window,
0, 0, 0, 0, 0, false, false, false, false, 0, null);
var cb = document.getElementById(type+"ViewMenu");
cb.dispatchEvent(evt);
if (this.selected)
document.getElementById(this.selected+"ViewMenu").removeAttribute("checked");
else {
document.getElementById("detailsViewMenu").removeAttribute("checked");
}
document.getElementById(type+"ViewMenu").setAttribute("checked","true");
document.getElementById("viewMenuPopup").setAttribute("view",type);
dump("type: "+type+"\n");
if (type=="details"){
if (!event || this.contentDeck.selectedIndex!=0 ||
this.selected == "albums"){
this.contentDeck.selectedIndex=0;
if (AlbumView.initiated)
AlbumViewUtils.uninit();
if (ThumbView.initiated)
ThumbViewUtils.uninit();
}
}
else if (type=="albums"){
if (!event || this.contentDeck.selectedIndex!=0 ||
this.selected == "details"){
this.contentDeck.selectedIndex=0;
/* refresh if this wasn't selected and isn't the first view
if it is the first view it will be updated by a container open call so
we don't need to refresh here, too.
*/
var refresh = this.selected&&this.selected!="albums";
if (ThumbViewUtils.initiated)
ThumbViewUtils.uninit();
AlbumViewUtils.initDisplay(refresh);
}
} else if (type=="thumbnails"){
if (!event || this.contentDeck.selectedIndex!=1){
this.contentDeck.selectedIndex=1;
if (AlbumView.initiated){
AlbumViewUtils.uninit();
}
//else
{/* first load, give time for the contents to get set up */
setTimeout(function(){ThumbViewUtils.initDisplay();},0);
}
}
}
this.selected = type;
},
getViewRoot : function(aCurIndex, aRootIndex){
var root;
var content = PlacesOrganizer._content;
var curIndex = content.currentIndex;
var rootIndex = -1;
root = content.getResultNode();
PlacesPreviewUtils.displayRoot = root;
if (aCurIndex)
aCurIndex.value = curIndex;
if (aRootIndex)
aRootIndex.value = rootIndex;
return root;
},
getImageForURL : function(aURL){
var nopreview = "chrome://bookmarkpreviews/skin/nopreview.png";
if (aURL){
var file = PreviewServiceUtils.getPreviewFile(aURL,this.dir);
if (file && file.exists() && file.isFile()){
var ios = Cc["@mozilla.org/network/io-service;1"].getService(Ci.nsIIOService);
var uri = ios.newFileURI(file);
if (uri)
return uri.spec;
}
}
return nopreview;
},
getBookmarkImages : function(bkmks, aNode){
/*
var previews = new PreviewProvider(aNode);
this.loading = true;
var open = previews.root.containerOpen;
if (!open)
previews.root.containerOpen = true;
var length = previews.length;
for (var i = 0; i<length;i++){
var bkmk = previews.getImage(i);
if (bkmk)
bkmks.push(bkmk);
}
if (!open)
previews.root.containerOpen = false;
this.loading = false;
*/
if (!aNode)
aNode = PlacesPreviewUtils.getViewRoot();
var self = PlacesPreviewUtils;
var view = PlacesOrganizer._content.getResultView();
var idx = view.treeIndexForNode(aNode);
if (idx == 4294967295) idx=-1;
idx=-1;
var isOpen = idx==-1 || view.isContainerOpen(idx);
var rowCount = view.rowCount;
if (!(rowCount==0 || idx>=rowCount)){
var level = view.getLevel(idx+1);
for (var i = idx+1; i<rowCount; i++){
var rowLevel = view.getLevel(i);
if (rowLevel==level){
var node = view.nodeForTreeIndex(i);
var aType = node.type;
if (aType!=Ci.nsINavHistoryResultNode.RESULT_TYPE_SEPARATOR){
var url = node.uri;
var name = node.title;
var image = null;
if (!(node instanceof Ci.nsINavHistoryContainerResultNode))
image = PlacesPreviewUtils.getImageForURL(url);
else
image = "chrome://bookmarkpreviews/skin/folder.png";
bkmks.push({image: image,
caption: name && name.length>0?name:url,
url: url,
node: node});
}
}
else if (rowLevel<level){
break;
}
}
}
},
canDrop : function(index, orientation){},
onDrop : function(row, orientation){},
onToggleOpenState : function(index){},
onCycleHeader : function(column){},
onCycleCell : function(row, column){},
onSelectionChanged : function(event){
//dump("onselectionchanged: "+event+"\n");
if (PlacesPreviewUtils.utils.bkmksTree &&
PlacesPreviewUtils.utils.bkmksTree.view!=PlacesPreviewUtils.utils.view){
PlacesPreviewUtils.utils.view = PlacesPreviewUtils.utils.bkmksTree.view;
}
//dump("selection changed - "+AlbumView.updatedSelection+" - \n");
if (!PlacesPreviewUtils.utils.updatedSelection){
/*
This listens to the detailed view and the folder view.
Although the selection of the detailed view is updated in time when
this is sent from the detailed view's tree, it isn't updated
in time when it is sent from a selection change from the folder
view
*/
setTimeout(function selectionChangedTimeout(){
PlacesPreviewUtils.utils.keepFocus = false
PlacesPreviewUtils.utils.refreshDisplay();
PlacesPreviewUtils.utils.keepFocus = true;
},5);
}
},
onPerformAction : function(action){
//dump("performaction\n");
},
onPerformActionOnRow : function(action, row){},
onPerformActionOnCell : function(action, row, column){},
observe: function(subject, topic, data) {
//dump("observer: "+topic+"|"+subject+"\n");
if (topic == "bookmarkpreviews:preview-updated"){
/* subject = updated uri */
this.utils.updatePreview(subject);
}
},
createPreviews : function(){
var strbundleService = Components.classes ["@mozilla.org/intl/stringbundle;1"]
.getService(Components.interfaces.nsIStringBundleService);
var bundle = strbundleService.createBundle("chrome://bookmarkpreviews/locale/strings.properties");
var dialogQ = bundle.GetStringFromName("createpreviewsmessage");
var dialogTitle = bundle.GetStringFromName("createpreviewsdialogtitle");
var prompts = Components.classes["@mozilla.org/embedcomp/prompt-service;1"]
.getService(Components.interfaces.nsIPromptService);
var result = prompts.confirm(window, dialogTitle, dialogQ);
if (result){
var wm = Components.classes["@mozilla.org/appshell/window-mediator;1"]
.getService(Components.interfaces.nsIWindowMediator);
var newWindow = wm.getMostRecentWindow("navigator:browser");
if (newWindow)
newWindow.PreviewService.generateAllPreviews();
//XXX do something if there is no preview window...
}
}
}
var AlbumViewUtils = {
displayView : null,
placesTree : null,
bkmksTree : null,
view : null,
canSelect : false,
get displayRoot(){
return PlacesPreviewUtils.displayRoot;
},
set displayRoot(val){
PlacesPreviewUtils.displayRoot = val;
},
initDisplay : function(aForceRefresh){
//dump("init albumview display\n");
AlbumViewUtils.displayView = AlbumView;
PlacesPreviewUtils.utils = AlbumViewUtils;
AlbumViewUtils.placesTree = PlacesOrganizer._places;
AlbumViewUtils.bkmksTree = PlacesOrganizer._content;
AlbumViewUtils.view = AlbumViewUtils.bkmksTree.view;
AlbumView.init();
AlbumView.container.collapsed = false;
if (aForceRefresh)
AlbumViewUtils.refreshDisplay(true);
},
uninit : function(){
this.initiated = false;
AlbumView.container.collapsed = true;
AlbumView.uninit();
},
onResize : function(event){
if (AlbumView.canRefresh){
var orient = 1;
if (event.target.id == "placesView" || event.target.id == "bookmark-views-splitter")
orient = 0;//Horizontal
AlbumView.refresh(orient);
}
},
_findNodeWithURI : function(root,uri){
if (root.uri == uri) return root;
for (var i=0;i<root.childCount;i++){
var child = root.getChild(i);
if (child.uri == uri)
return child;
if (child instanceof Components.interfaces.nsINavHistoryContainerResultNode){
child=child.QueryInterface(Components.interfaces.nsINavHistoryContainerResultNode);
if (child.containerOpen){
if ((child = AlbumViewUtils._findNodeWithURI(child,uri)))
return child;
}
}
}
return null;
},
refreshDisplay : function(aForceRefresh, what){
//dump('refreshdisplay: '+aForceRefresh+" - ");
var curIndexObj = new Object(), rootIndexObj = new Object();
var previousRoot = AlbumViewUtils.displayRoot;
var root = PlacesPreviewUtils.getViewRoot(curIndexObj, rootIndexObj);
var curIndex = curIndexObj.value, rootIndex = rootIndexObj.value;
if (root!=previousRoot || (aForceRefresh && !this.loading)){
var bkmks=[];
AlbumView.clearItems();
AlbumView.current = AlbumView.target = 0;
var previews = new PreviewProvider(root);
this.loading = true;
this._loadItems(previews);
}
var nextTarget=AlbumViewUtils._getNextTarget(curIndex,rootIndex);
AlbumView.keepFocus = false;
AlbumView.refresh(-1);
if (!(curIndex>-1 && AlbumViewUtils.view.isSeparator(curIndex)))
AlbumView.glideToIndex(nextTarget);
this.initiated = true;
},
_loadItems : function(aPreviews, aStart){
var length = aPreviews.length, i;
var start = i = aStart?aStart:0;
for (; i<length && i-start<15;i++){
var bkmk = aPreviews.getImage(i);
if (bkmk)//Might be a separator
AlbumView.addItem(bkmk);
}
if (i>=length){
this.loading = false;
} else {
setTimeout(function(a){
if (a.displayRoot == aPreviews.root)
a._loadItems(aPreviews,i);
},50,this);
}
},
_getNextTarget : function(cIndex,rIndex){
if (cIndex>rIndex+1){
var max = AlbumViewUtils.view.rowCount, level = AlbumViewUtils.view.getLevel(cIndex);
var nextTarget = 0;//rIndex==-1?-1:0;
for (var i = rIndex+1;i<cIndex;i++){
if (AlbumViewUtils.view.getLevel(i)==level &&
!AlbumViewUtils.view.isSeparator(i))
nextTarget++;
}
return nextTarget;
}
return 0;
},
updatePreview : function(aURI){
//dump("update album preview: "+aURI.spec+"\n");
aURI = aURI.QueryInterface(Components.interfaces.nsIURI);
for (var i = 0; i < AlbumView.max; i++){
var url = AlbumView.itemProps[i].url;
if (url == aURI.spec){
var imgsrc = PlacesPreviewUtils.getImageForURL(url);
AlbumView.itemImages[i]=new Image();
AlbumView.itemImages[i].onload = function(){
AlbumView.imageLoaded(i);
}
AlbumView.itemImages[i].src = imgsrc;
if (AlbumView.itemImages[i].complete){
AlbumView.imageLoaded(i);
}
break;
}
}
},
selectIndex : function(node){
if (AlbumViewUtils.keepFocus){
AlbumViewUtils.updatedSelection = true;
if (!(AlbumViewUtils.bkmksTree.hasSelection &&
AlbumViewUtils.bkmksTree.hasSingleSelection &&
AlbumViewUtils.bkmksTree.selectedNode == node && node)){
AlbumViewUtils.view.selection.clearSelection();
//AlbumViewUtils.bkmksTree.selectItems([node.itemId]);
try{
var view = AlbumViewUtils.bkmksTree.view.QueryInterface(Ci.nsINavHistoryResultTreeViewer);
var index = view.treeIndexForNode(node);
view.selection.select(index);
AlbumViewUtils.bkmksTree.treeBoxObject.ensureRowIsVisible(index);
}catch(e){
dump("bp select index e: "+e+"\n");
}
}
AlbumViewUtils.updatedSelection = false;
}
AlbumViewUtils.keepFocus = true;
},
performAction : function(node, event){
if (PlacesUtils.nodeIsBookmark(node)){
openUILink(node.uri,event);
}
else if (PlacesUtils.nodeIsContainer(node)){
AlbumViewUtils.placesTree.selectItems([node.itemId]);
//dump("perform action refresh\n");
AlbumViewUtils.refreshDisplay();
}
}
}
var ThumbViewUtils = {
displayView : null,
placesTree : null,
view : null,
initDisplay : function(){
//dump("init thumbview display\n");
ThumbViewUtils.displayView = ThumbView;
ThumbViewUtils.placesTree = PlacesOrganizer._places;
PlacesPreviewUtils.utils = ThumbViewUtils;
document.getElementById('thumbsSize').removeAttribute("disabled");
this.refreshDisplay(true);
//this.selectItem(item);
this.initiated = true;
//dump("finish init thumbview display\n");
},
uninit : function(){
this.initiated = false;
document.getElementById('thumbsSize').setAttribute("disabled","true");
/* select the current items in the content tree */
var selectedNode = ThumbView.selectedNode;
if (selectedNode)
PlacesOrganizer._content.selectItems([selectedNode.itemId]);
},
refreshDisplay : function(aForceRefresh){
this.initiated = true;
var previousRoot = PlacesPreviewUtils.displayRoot;
var root = PlacesPreviewUtils.getViewRoot();
if (aForceRefresh || !previousRoot || previousRoot.itemId!=root.itemId){
ThumbView.place = root.uri;
} else{
var bkmks = [];
PlacesPreviewUtils.getBookmarkImages(bkmks);
ThumbView.load(bkmks);
}
},
onResize : function(event){
ThumbView.onResize(event);
},
updatePreview : function(aURI){
//dump("update preview: "+aURI+"\n");
aURI = aURI.QueryInterface(Components.interfaces.nsIURI);
ThumbView.updateThumbnail(aURI.spec);
},
updateNodeTitle : function(aNode, aPrevVal, aNewVal){
ThumbView.updateNodeTitle(aNode,aPrevVal,aNewVal);
},
back : function(){PlacesOrganizer.back();},
forward : function(){PlacesOrganizer.forward();},
getBookmarkImages : PlacesPreviewUtils.getBookmarkImages,
_getNextTarget : function(cIndex,rIndex){
if (cIndex>rIndex+1){
var max = ThumbViewUtils.view.rowCount, level = ThumbViewUtils.view.getLevel(cIndex);
var nextTarget = 0;//rIndex==-1?-1:0;
for (var i = rIndex+1;i<cIndex;i++){
if (ThumbViewUtils.view.getLevel(i)==level &&
!ThumbViewUtils.view.isSeparator(i))
nextTarget++;
}
return nextTarget;
}
return 0;
},
selectIndex : function(node){
ThumbViewUtils.updatedSelection = true;
ThumbViewUtils.bkmksTree.selectItems([node.itemId]);
//ThumbViewUtils.selectNode(ThumbViewUtils.bkmksTree,node);
ThumbViewUtils.updatedSelection = false;
},
selectItem : function(item, event){
ThumbViewUtils.updatedSelection = true;
if (gEditItemOverlay.itemId != -1) {
var focusedElement = document.commandDispatcher.focusedElement;
if ((focusedElement instanceof HTMLInputElement ||
focusedElement instanceof HTMLTextAreaElement) &&
/^editBMPanel.*/.test(focusedElement.parentNode.parentNode.id))
focusedElement.blur();
}
var contentTree = document.getElementById("placeContent");
var detailsDeck = document.getElementById("detailsDeck");
var infoBox = document.getElementById("infoBox");
/* infoBox = 3.0pre, infoScrollBox = 3.0b5 */
if (!infoBox) {
infoBox = document.getElementById("infoScrollBox");
if (!infoBox) infoBox = {hidden:false};
}
detailsDeck.selectedIndex = 1;
if (item && item.node) {
var selectedNode = item.node;
infoBox.hidden = false;
if (selectedNode && selectedNode.itemId != -1) {
if (PlacesOrganizer._paneDisabled) {
PlacesOrganizer._setDetailsFieldsDisabledState(false);
PlacesOrganizer._paneDisabled = false;
}
// Using the concrete itemId is arguably wrong. The bookmarks API
// does allow setting properties for folder shortcuts as well, but since
// the UI does not distinct between the couple, we better just show
// the concrete item properties.
if (selectedNode.type ==
Ci.nsINavHistoryResultNode.RESULT_TYPE_FOLDER_SHORTCUT) {
gEditItemOverlay.initPanel(asQuery(selectedNode).folderItemId,
{ hiddenRows: ["folderPicker"],
forceReadOnly: true });
} else {
gEditItemOverlay.initPanel(selectedNode.itemId,
{ hiddenRows: ["folderPicker"] });
}
PlacesOrganizer._detectAndSetDetailsPaneMinimalState(selectedNode);
ThumbViewUtils.updatedSelection = false;
return;
}
}
else {
detailsDeck.selectedIndex = 0;
// The details deck has the height of its biggest child, so we hide the
// infoBox to allow it shrinking when there is no selection.
infoBox.hidden = true;
var selectItemDesc = document.getElementById("selectItemDescription");
var itemsCountLabel = document.getElementById("itemsCountText");
var rowCount = ThumbView.bookmarks.length;
if (rowCount == 0) {
selectItemDesc.hidden = true;
itemsCountLabel.value = PlacesUIUtils.getString("detailsPane.noItems");
}
else {
selectItemDesc.hidden = false;
if (rowCount == 1)
itemsCountLabel.value = PlacesUIUtils.getString("detailsPane.oneItem");
else {
itemsCountLabel.value =
PlacesUIUtils.getFormattedString("detailsPane.multipleItems",
[rowCount]);
}
}
}
// Nothing to do if the pane was already disabled
if (!PlacesOrganizer._paneDisabled) {
gEditItemOverlay.uninitPanel();
PlacesOrganizer._setDetailsFieldsDisabledState(true);
PlacesOrganizer._paneDisabled = true;
}
ThumbViewUtils.updatedSelection = false;
},
performAction : function(item, event){
var node = item.node;
if (PlacesUtils.nodeIsBookmark(node)){
openUILink(node.uri,event);
}
else if (PlacesUtils.nodeIsContainer(node)){
//ThumbViewUtils.selectPlaceURI(PlacesOrganizer._places,node.uri);
ThumbViewUtils.placesTree.selectItems([node.itemId]);
//PlacesOrganizer.location = node.uri;
}
},
removeItem : function(item, event){
var node = item.node;
PlacesUtils.bookmarks.removeItem(node.itemId);
ThumbViewUtils.refreshDisplay();
}
}
window.addEventListener('load',PlacesPreviewUtils.init,false);
window.addEventListener('unload',PlacesPreviewUtils.uninit,false);